package com.cz.kingdee.test;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import com.cz.kingdee.KingdeeClient;
import com.cz.kingdee.dto.ManufactureOrderDetail;
import com.kingdee.bos.webapi.entity.QueryParam;
import com.kingdee.bos.webapi.sdk.K3CloudApi;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class ManufactureOrderLocalDiff {
    public static void main(String[] args) {
        try {
            KingdeeClient kingdeeClient = new KingdeeClient();
            K3CloudApi k3CloudApi = kingdeeClient.getTestKingdeeClient();

            List<Entity> entityList = Db.use().query("select mo.bill_no,modt.sku_code,sku_name from manufacture_order_detail modt inner join manufacture_order mo on modt.main_id = mo.id" +
                    " where modt.status = 1 and mo.status =1");
            Map<String, List<Entity>> groupByBillNO = entityList.stream().collect(Collectors.groupingBy(entity -> entity.getStr("bill_no")));
            groupByBillNO.keySet().forEach(billNO -> {
                QueryParam queryParam = new QueryParam();
                queryParam.setFormId("PRD_MO");
                queryParam.setFieldKeys("FID,FBillNo");
                queryParam.setFilterString("FBillNo = '"+billNO+"'");

                try {
                    List<ManufactureOrderDetail> manufactureOrderDetailList = k3CloudApi.executeBillQuery(queryParam, ManufactureOrderDetail.class);
                    if(CollUtil.isEmpty(manufactureOrderDetailList)){
                        System.out.println("billNo:"+billNO+",在金蝶系统上不存在");
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }

            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
